package com.atan.xiaohongshu.auth.alarm;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.atan.xiaohongshu.auth.alarm.impl.EmailAlarmHelper;
import com.atan.xiaohongshu.auth.alarm.impl.SmsAlarmHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RefreshScope
public class AlarmConfig {

    @Value("${alarm.type}")
    private String alarmType;

    @Bean
    @RefreshScope
    public AlarmInterface alarmInterface() {
        // 根据配置的报警类型，返回对应的实现类
        if ("email".equals(alarmType)) {
            return new EmailAlarmHelper();
        } else if ("sms".equals(alarmType)) {
            return new SmsAlarmHelper();
        } else {
            throw new IllegalArgumentException("Unsupported alarm type: " + alarmType);
        }
    }
}
